﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
#if !NETFX_CORE && !UNIVERSAL
using System.Windows;
using System.Windows.Media;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
#endif
namespace Prometheus.UIUtility
{
    public static class SilverLightTookitImpl
    {
        /// <summary>
        /// Get the visual tree ancestors of an element and the element itself.
        /// 
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>
        /// The visual tree ancestors of an element and the element itself.
        /// 
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="element"/> is null.
        ///             </exception>
        public static IEnumerable<DependencyObject> GetVisualAncestorsAndSelf(this DependencyObject element)
        {
            if (element == null)
                throw new ArgumentNullException("element");
            return GetVisualAncestorsAndSelfIterator(element);
        }

        /// <summary>
        /// Get the visual tree ancestors of an element and the element itself.
        /// 
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>
        /// The visual tree ancestors of an element and the element itself.
        /// 
        /// </returns>
        private static IEnumerable<DependencyObject> GetVisualAncestorsAndSelfIterator(DependencyObject element)
        {
            Debug.Assert(element != null, "element should not be null!");
            for (DependencyObject obj = element; obj != null; obj = VisualTreeHelper.GetParent(obj))
                yield return obj;
        }
    }
}